/******************************************************************************
 * @file bsp_led_driver.h
 *
 * @par dependencies
 *  - stdint.h
 *
 * @brief bsp driver for LED control
 *
 * Processing flow:
 *
 * call directly.
 *
 * @author iceiceiceberg
 *
 * @date 2025-05-11
 *
 * @version V1.0.0
 *
 * @note 1 tab == 4 spaces
 *
 *****************************************************************************/
#ifndef __BSP_LED_DRIVER_H__
#define __BSP_LED_DRIVER_H__

//********************************* Includes ********************************//
#include <stdint.h>
#include <stdio.h>

//********************************* Includes ********************************//

//********************************* Defines *********************************//
#define OS_SUPPORT
#define DEBUG
//#define SYSTEM_QUICK_BOOT

#define DEBUG_PRINT(...) printf(__VA_ARGS__)

#define LED_IS_INSTED     (1U)
#define LED_IS_NOT_INSTED (0U)

typedef struct bsp_led_driver bsp_led_driver_t;

typedef enum
{
    LED_OK                = 0,                  /* No error                  */
    LED_ERROR             = 1,                  /* General error             */
    LED_ERROR_RESOURCE    = 2,                  /* Error resource            */
    LED_ERROR_TIMEOUT     = 3,                  /* Timeout error             */
    LED_ERROR_PARAM       = 4,                  /* Parameter error           */
    LED_ERROR_MEMORY      = 5,                  /* Memory allocation error   */
    LED_RESERVED          = 0xFF                /* Reserved                  */
} led_state_t;

typedef enum
{
    PROPORTION_ON_OFF_1_1 = 0,                  /* 1:1 proportion ON OFF     */
    PROPORTION_ON_OFF_1_2 = 1,                  /* 1:2 proportion ON OFF     */
    PROPORTION_ON_OFF_1_3 = 2,                  /* 1:3 proportion ON OFF     */
    PROPORTION_ON_OFF_X_X = 0xFF,               /* Custom proportion ON OFF  */
} blink_proportion_t;

typedef struct
{
    led_state_t (*pf_led_on)  (void);           /* LED on function pointer   */
    led_state_t (*pf_led_off) (void);           /* LED off function pointer  */
} led_opes_t;

typedef struct bsp_led_driver
{
    /* Driver instance flag                              */
    uint8_t                                is_instantiated; 

    /************* Blink ways configuration **************/
    /* Period in milliseconds                            */
    uint32_t                               cycle_period_ms;
    /* LED blink times                                   */ 
    uint32_t                                   blink_times; 
    /* Proportion on and off                             */
    blink_proportion_t             blink_proportion_on_off; 

    /************* Interface pointers ********************/
    /* LED operation interface from GPIO                 */
    led_opes_t                         *p_led_ops_instance; 
} bsp_led_driver_t;

//********************************* Defines *********************************//

//********************************* Declaring *******************************//
/**
 * @brief Instantiates the bsp_led_driver_t target.
 * 
 * Steps:
 *  1. Adds Core interfaces into bsp_led_driver instance target.
 *  2. Adds timebase interfaces into bsp_led_driver instance target.
 *  3. Adds OS interfaces into bsp_led_driver instance target.
 *  
 * @param[in] self        : Pointer to the target of driver.
 * @param[in] led_ops     : Pointer to the led_opes_t interface.
 * @param[in] sys_time    : Pointer to the core_base_time_ms_t interface.
 * @param[in] os_delay    : Pointer to the os_delay_interface.
 * 
 * @return led_state_t : Status of the function.
 * 
 * */
led_state_t bsp_led_driver_inst ( bsp_led_driver_t    * const        self, 
                                  led_opes_t          * const   led_ops );

//********************************* Declaring *******************************//

#endif // __BSP_LED_DRIVER_H__
